const download = require('download-git-repo')
const ora = require('ora')
const chalk = require('chalk')
const downloadFun = (project, url) => {
  const spinner = ora()
  spinner.text = '代码正在下载...'
  spinner.start()
  download(
    `direct:${url}`,
    project,
    { clone: true },
    (err) =>{
      if (!err) {
        spinner.succeed('下载成功')
        console.log(chalk.green('Done! you can run: '))
        console.log(chalk.bold.hex('#ff5a33')('cd ' + project))
        console.log(chalk.rgb(67, 68, 98)('npm install '))
        console.log('npm run dev ')
      } else {
        spinner.fail('下载失败')
      }
    }
  )
}

module.exports = downloadFun